package xin.nick;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import xin.nick.bean.ConsumerComponent;
import xin.nick.bean.TpMonitorFilter;

import java.io.IOException;
import java.util.TreeMap;
import java.util.concurrent.*;

/**
 * @author Nick
 * @date 2021/7/18
 * @description
 */
public class ConsumerMain {
    private static final Logger logger =
            LoggerFactory.getLogger(ConsumerMain.class);

    public static void main(String[] args) {

        AnnotationConfigApplicationContext context =
                new AnnotationConfigApplicationContext(ConsumerConfiguration.class);

        context.start();

        ConsumerComponent service = context.getBean(ConsumerComponent.class);

        logger.info("消费者启动...");


        TpMonitorFilter tpMonitorFilter = new TpMonitorFilter();
        // 利用定时线程来定时刷日志
         Executors.newSingleThreadScheduledExecutor()
                .scheduleWithFixedDelay(tpMonitorFilter, 5,5, TimeUnit.SECONDS);

        service.callMethod1();
        service.callMethod2();
        service.callMethod3();

        logger.info("开始轰炸...");
//        while (true) {
//            try {
//                System.in.read();
////                service.callMethod1();
////                service.callMethod2();
//                service.callMethod3();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }

    }

    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(basePackages = "xin.nick.bean")
    @EnableDubbo
    static class ConsumerConfiguration {

    }
}
